<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\adminapi\controller\skits;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\skits\SkitsLists;
use app\adminapi\logic\skits\SkitsLogic;
use app\adminapi\validate\skits\SkitsValidate;
use app\common\service\douyin\DouyinService;


/**
 * Skits控制器
 * Class SkitsController
 * @package app\adminapi\controller
 */
class SkitsController extends BaseAdminController
{


    /**
     * @notes 获取列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function lists()
    {
        return $this->dataLists(new SkitsLists());
    }


    /**
     * 获取所有短剧
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getAll()
    {
        return $this->data(SkitsLogic::getAll($this->request->get('app_id')));
    }



    /**
     * @notes 添加
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function add()
    {
        $params = (new SkitsValidate())->post()->goCheck('add');
        $result = SkitsLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }

        return $this->fail(SkitsLogic::getError());
    }


    /**
     * @notes 编辑
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function edit()
    {
        $params = (new SkitsValidate())->post()->goCheck('edit');
        $result = SkitsLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(SkitsLogic::getError());
    }

    /**
     * @notes  批量更改状态
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/21 10:15
     */
    public function batchUpdateStatus()
    {
        $params = (new SkitsValidate())->post()->goCheck('batchUpdateStatus');
        $result = SkitsLogic::batchUpdateStatus($params);
        if (true === $result) {
            return $this->success('修改成功', [], 1, 1);
        }
        return $this->fail(SkitsLogic::getError());
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function delete()
    {
        $params = (new SkitsValidate())->post()->goCheck('delete');
        SkitsLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function detail()
    {
        $params = (new SkitsValidate())->goCheck('detail');
        $result = SkitsLogic::detail($params);
        return $this->data($result);
    }


    /**
     * 获取微信提审详情
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getWechatAuditDramaList()
    {
        $skitsId = $this->request->get('skits_id', '');

        return $this->data(SkitsLogic::getWechatAuditDramaDetail($skitsId));
    }


    /**
     * 获取微信提审详情
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getWechatAuditDramaDetail()
    {
        $skitsId = $this->request->get('skits_id', '');

        return $this->data(SkitsLogic::getWechatAuditDramaDetail($skitsId));
    }


    /**
     * 微信提审
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function wechatAuditDrama()
    {
        $params = $this->request->post();

        return SkitsLogic::wechatAuditDrama($params) ?
            $this->success('提审成功') : $this->fail(SkitsLogic::getError());
    }


    /**
     * 获取微信媒资列表
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWechatMediaList()
    {
        $appId    = $this->request->get('app_id', '');
        $skitsId  = $this->request->get('skits_id', '');
        $pageNo   = $this->request->get('page_no', 0);
        $name     = $this->request->get('name', '');
        $pageSize = $this->request->get('page_size', 10);
        $result   = SkitsLogic::getWechatMediaList($appId, $skitsId, $name, $pageNo, $pageSize);
        if (!$result) {

            return $this->data([]);
        }

        return $this->data($result);
    }


    /**
     * 上传微信临时素材
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function uploadWechatMedia()
    {
        $appId  = $this->request->post('app_id', '');
        $file   = $this->request->file('file', '');
        $result = SkitsLogic::uploadWechatMedia($appId, $file);
        if (!$result) {
            $this->fail('上传失败');
        }

        return $this->data($result);
    }


    public function uploadDouyinPic()
    {
        $appId  = $this->request->post('app_id', '');
        $picUrl = $this->request->post('pic_url', '');
        $openId = $this->request->post('open_id', '');
        // DouyinService::queryVideo($appId, $openId);
        $result = SkitsLogic::uploadDouyinPic($appId, $picUrl);
        if (!$result) {
            $this->fail('上传失败');
        }

        return $this->data($result);
    }


    /**
     * 创建抖音短剧
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function createDouyinVideo()
    {
        $params = $this->request->post();

        return SkitsLogic::createDouyinVideo($params) ? $this->success('创建成功', [], 1, 1) : $this->fail(SkitsLogic::getError());
    }


    /**
     * 编辑抖音短剧/添加剧集
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function editDouyinVideo()
    {
        $params = $this->request->post();

        return SkitsLogic::editDouyinVideo($params) ? $this->success('成功', [], 1, 1) : $this->fail(SkitsLogic::getError());
    }


    /**
     * 抖音短剧送审
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function douyinVideoReview()
    {
        $params = $this->request->post();

        return SkitsLogic::douyinVideoReview($params) ? $this->success('成功', [], 1, 1) : $this->fail(SkitsLogic::getError());
    }


    /**
     * 抖音短剧授权
     *
     * @return \think\response\Json
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function authDouyinVideo()
    {
        $params = $this->request->post();

        return SkitsLogic::authDouyinVideo($params) ? $this->success('成功', [], 1, 1) : $this->fail(SkitsLogic::getError());
    }
}
